prevent user.uuid from being regenerated on each operation by reading it from the DB#12632
prevent user.uuid from being regenerated on each operation by reading it from the DB#12632DaanHoogland merged 6 commits into4.20from
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.20 #12632 +/- ##
============================================
- Coverage 16.25% 16.25% -0.01%
- Complexity 13421 13433 +12
============================================
Files 5662 5662
Lines 500141 500580 +439
Branches 60728 60969 +241
============================================
+ Hits 81299 81365 +66
- Misses 409759 410128 +369
- Partials 9083 9087 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #12612 where API-key authentication could yield a different (random) user UUID per request, by ensuring the user’s UUID is read from the database and propagated into the User object used in auth/context.
Changes:
- Update the
FIND_USER_ACCOUNT_BY_API_KEYquery and result mapping to include and setu.uuid. - Adjust
UserVO(long id)initialization to delegate to the no-arg constructor. - Extend the
com.cloud.user.Userinterface to includesetUuid(String).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java | Adds UUID to the API-key lookup query and maps it into the User instance. |
| engine/schema/src/main/java/com/cloud/user/UserVO.java | Changes the UserVO(long id) constructor to call this() before setting id. |
| api/src/main/java/com/cloud/user/User.java | Adds setUuid(String uuid) to the User interface. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@DaanHoogland |
no doubt, but can you be more specific? Do you mean, bypass Note |
@DaanHoogland |
…ountDao.getUserByApiKey(encodedKey)`
ok, gave it a stab, |
good, look forward to your more changes |
|
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16831 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15494)
|
|
@blueorangutan test keepEnv |
1 similar comment
|
@blueorangutan test keepEnv |
|
@abh1sar a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15504)
|
RosiKyu
left a comment
There was a problem hiding this comment.
LGTM
| # | Test Case | Method | Status |
|---|---|---|---|
| TC1 | User UUID is consistent across repeated API-key authenticated requests and matches DB value | curl + mysql | PASS |
| TC2 | Normal API key authentication works correctly (no regression) | curl | PASS |
Result: 2/2 PASS
Verified that API key authentication now returns the correct user UUID from the database consistently across multiple requests, fixing the random UUID generation issue described in #12612. No regressions observed in normal API key authentication flow.
TC1: User UUID is consistent across repeated API-key authenticated requests
Objective Verify that API key authentication returns the same (correct) user UUID on every request, instead of generating a random UUID each time (the original bug described in #12612).
Test Steps
- As RootAdmin, create a regular User account
uuidtest - Register API keys for the user
- Confirm the user's UUID in the database:
SELECT id, uuid, username FROM cloud.user WHERE username='uuidtest'; - Using curl with API key signature authentication, call an admin-only API (
listHosts) 3 times as theuuidtestuser - Compare the UUID in each error response to each other and to the DB value
Expected Result: All 3 error responses should contain the same user UUID, and it should match the UUID stored in the database (0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1).
Actual Result: All 3 responses returned the identical UUID 0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1, matching the database value.
Test Evidence:
# Database UUID:
mysql> SELECT id, uuid, username FROM cloud.user WHERE username='uuidtest';
+----+--------------------------------------+----------+
| id | uuid | username |
+----+--------------------------------------+----------+
| 5 | 0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1 | uuidtest |
+----+--------------------------------------+----------+
# API responses (3 consecutive requests):
=== Request 1 ===
"errortext": "The API [listHosts] does not exist or is not available for the account for user id [0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1]."
=== Request 2 ===
"errortext": "The API [listHosts] does not exist or is not available for the account for user id [0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1]."
=== Request 3 ===
"errortext": "The API [listHosts] does not exist or is not available for the account for user id [0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1]."
TC2: Normal API key authentication works correctly (no regression)
Objective Verify that API key authentication continues to work for permitted API calls after the refactoring, and that the returned user UUID matches the database value.
Test Steps
- Using the same
uuidtestuser with API key authentication - Call a permitted API (
listAccounts) via curl with API key signature - Verify the call succeeds and the user UUID in the response matches the database value
Expected Result: The API call should succeed (HTTP 200, valid response) and the user id field in the response should match the database UUID (0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1).
Actual Result: The listAccounts API returned successfully with the uuidtest account details. The user id in the response is 0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1, matching the database value.
Test Evidence:
# API response (successful listAccounts via API key auth):
{
"listaccountsresponse": {
"count": 1,
"account": [{
"id": "1212ec3c-c3a4-4b21-8429-3966a10a82b0",
"name": "uuidtest",
"user": [{
"id": "0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1",
"username": "uuidtest",
"apikey": "2pzbGDWWJW66tSOcjwJx1_FP6HxO971EJ4Wkcp0eQhy8iIMiXndWowsALbVLi5kAmN0dvRNorTCkMXY_Usl6SQ",
...
}]
}]
}
}
# Database UUID (confirmed in TC1):
0d5fe11a-ea49-4ea7-9bc6-6b3ede0af4d1 MATCH
|
thanks @RosiKyu @DaanHoogland |


Description
This PR implements the reporters suggestion as requested...
Fixes: #12612
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?